package org.han.permission.controller;

import org.han.annotation.RonghuanetPermission;
import org.han.permission.domain.Permission;
import org.han.permission.query.PermissionQuery;
import org.han.permission.service.IPermissionService;
import org.han.util.AjaxResult;
import org.han.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
@RonghuanetPermission(name = "权限管理",desc="权限查询")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @RonghuanetPermission(name = "分页查询")
    @PostMapping
    public AjaxResult listPage(@RequestBody PermissionQuery query){
        System.out.println(query.getCurrentPage());
        try {
            PageList pageList = permissionService.pageList(query);
            return AjaxResult.me().setData(pageList);

        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("查询失败~~" + e.getMessage());
        }
    }

    @GetMapping("/tree")
    @RonghuanetPermission(name = "查询权限树")
    public AjaxResult tree(){
        try {
            List<Permission> tree = permissionService.tree();
            return AjaxResult.me().setData(tree);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("查询失败~~" + e.getMessage());
        }
    }
}
